package com.chuyu.jzwboa.activity.notice;

import android.graphics.drawable.BitmapDrawable;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chuyu.jzwboa.R;
import com.chuyu.jzwboa.adapter.notice.NoticeAdapter;
import com.chuyu.jzwboa.adapter.notice.NoticePopupWindowAdapter;
import com.chuyu.jzwboa.base.MVPBaseActivity;
import com.chuyu.jzwboa.presenter.notice.NoticePresenter;
import com.chuyu.jzwboa.utils.sys.StatusBarUtils;
import com.chuyu.jzwboa.view.iview.notice.INoticeView;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * description  通知公告
 */
public class NoticeActivity extends MVPBaseActivity<INoticeView, NoticePresenter> implements INoticeView, View.OnClickListener {

	@BindView(R.id.tv_notice)
	TextView tvNotice;
	@BindView(R.id.rl_hitcard)
	RelativeLayout rlHitcard;
	@BindView(R.id.rl_search_notice)
	LinearLayout rlSearchNotice;
	@BindView(R.id.notice_recyclerview)
	XRecyclerView noticeRecyclerview;
	@BindView(R.id.iv_cancel_notice)
	ImageView ivCancelNotice;
	@BindView(R.id.rl_notice)
	RelativeLayout rlNotice;
	private NoticePresenter noticePresenter;
	private NoticeAdapter noticeAdapter;

	@NonNull
	@Override
	public NoticePresenter createPresenter() {
		noticePresenter = new NoticePresenter();
		return noticePresenter;
	}

	@Override
	protected int initContent() {
		return R.layout.activity_notice;
	}

	@Override
	protected void initView() {
		ivCancelNotice.setOnClickListener(this);
		rlNotice.setOnClickListener(this);
		LinearLayoutManager layoutManager = new LinearLayoutManager(this);
		layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
		noticeRecyclerview.setLayoutManager(layoutManager);
		noticeRecyclerview.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
	}

	@Override
	protected void initData() {
		/**
		 * 动态设置状态栏高度
		 */
		int statusHeight = StatusBarUtils.getStatusHeight(this);
		rlHitcard.setPadding(0, statusHeight, 0, 0);
		List<Integer> list = new ArrayList<>();
		list.add(1);
		list.add(1);
		list.add(1);
		list.add(1);
		noticeAdapter = new NoticeAdapter(getApplicationContext(), list);
		noticeRecyclerview.setAdapter(noticeAdapter);
	}

	@Override
	public void LoadSuccess() {

	}

	@Override
	public void LoadFailed() {

	}

	@Override
	public void LoadException() {

	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.iv_cancel_notice:
				finish();
				break;
			case R.id.rl_notice:
				showPopupWindow();
				break;
		}
	}

	/**
	 * 弹出通知公告类型
	 */
	private void showPopupWindow() {
		View inflate = LayoutInflater.from(getApplicationContext()).inflate(
				R.layout.popupwindow_notice, null);
		final PopupWindow mPopWindow = new PopupWindow(inflate,
				ViewPager.LayoutParams.FILL_PARENT, ViewPager.LayoutParams.WRAP_CONTENT, true);
		mPopWindow.setBackgroundDrawable(new BitmapDrawable());
		// 设置点击窗口外边窗口消失
		mPopWindow.setOutsideTouchable(true);
		// 设置此参数获得焦点，否则无法点击
		mPopWindow.setFocusable(true);
		mPopWindow.setContentView(inflate);
		mPopWindow.showAsDropDown(rlNotice, 0, 0);
		mPopWindow.setAnimationStyle(R.style.PopupAnimation);
		GridView gd_dailyimg = (GridView) inflate
				.findViewById(R.id.gd_dailyimg);
		View view4 = inflate
				.findViewById(R.id.view4);
		view4.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				mPopWindow.dismiss();
			}
		});
		List<String> list = new ArrayList<>();
		list.add("全部");
		list.add("人事通知");
		list.add("行政通知");
		NoticePopupWindowAdapter adapter = new NoticePopupWindowAdapter(getApplicationContext(), list);
		gd_dailyimg.setAdapter(adapter);
		gd_dailyimg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
				mPopWindow.dismiss();
//				view.setSelected(true);
			}
		});
	}


}
